package com.ruoyi.project.dict.guhanyu.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.guhanyu.domain.Guhanyu;
import com.ruoyi.project.dict.guhanyu.service.IGuhanyuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 汉语解释Controller
 *
 * @author shixiangwen
 * @date 2021-05-19
 */
@Controller
@RequestMapping("/dict/guhanyu")
public class GuhanyuController extends BaseController {
    private String prefix = "dict/guhanyu";

    @Autowired
    private IGuhanyuService guhanyuService;

    @RequiresPermissions("dict:guhanyu:view")
    @GetMapping()
    public String guhanyu() {
        return prefix + "/guhanyu";
    }

    /**
     * 查询汉语解释列表
     */
    @RequiresPermissions("dict:guhanyu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Guhanyu guhanyu) {
        startPage();
        List<Guhanyu> list = guhanyuService.selectGuhanyuList(guhanyu);
        return getDataTable(list);
    }

    /**
     * 导出汉语解释列表
     */
    @RequiresPermissions("dict:guhanyu:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Guhanyu guhanyu) {
        List<Guhanyu> list = guhanyuService.selectGuhanyuList(guhanyu);
        ExcelUtil<Guhanyu> util = new ExcelUtil<Guhanyu>(Guhanyu.class);
        return util.exportExcel(list, "guhanyu");
    }

    /**
     * 新增汉语解释
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存汉语解释
     */
    @RequiresPermissions("dict:guhanyu:add")
    @Log(title = "汉语解释", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Guhanyu guhanyu) {
        return toAjax(guhanyuService.insertGuhanyu(guhanyu));
    }

    /**
     * 修改汉语解释
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Guhanyu guhanyu = guhanyuService.selectGuhanyuById(id);
        mmap.put("guhanyu", guhanyu);
        return prefix + "/edit";
    }

    /**
     * 修改保存汉语解释
     */
    @RequiresPermissions("dict:guhanyu:edit")
    @Log(title = "汉语解释", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Guhanyu guhanyu) {
        return toAjax(guhanyuService.updateGuhanyu(guhanyu));
    }

    /**
     * 删除汉语解释
     */
    @RequiresPermissions("dict:guhanyu:remove")
    @Log(title = "汉语解释", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(guhanyuService.deleteGuhanyuByIds(ids));
    }
}
